package cn.iocoder.yudao.module.picturebook.controller.admin.login;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.picturebook.controller.admin.login.vo.LoginRequest;
import cn.iocoder.yudao.module.picturebook.controller.admin.login.vo.LoginResponse;
import cn.iocoder.yudao.module.picturebook.service.login.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Tag(name = "绘本系统 - 登录")
@RestController
@RequestMapping("/picturebook")
@Validated
public class LoginController {
    @Resource
    private AuthService authService;
    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public CommonResult<LoginResponse> login(@Validated LoginRequest reqVO) {
        LoginResponse response = authService.authenticateUser(reqVO.getUsername(), reqVO.getPassword());
        if (response == null || response.getToken() == null) {
            return CommonResult.error(303, "登录失败,账号或密码错误！");
        }
        return CommonResult.success(response);
    }
}
